#!/usr/bin/env python3
# -*- coding: utf-8 -*-

"""
检查数据库中的测试用例数据
"""

from app import create_app
from models import db, Problem

def check_test_cases():
    """检查数据库中的测试用例数据"""
    app = create_app()
    
    with app.app_context():
        # 获取所有编程题
        code_problems = Problem.query.filter(Problem.type.in_(['code', 'code_completion'])).all()
        
        print(f"找到 {len(code_problems)} 个编程题")
        
        for problem in code_problems:
            print(f"\n题目ID: {problem.id}")
            print(f"题目标题: {problem.title}")
            print(f"题目类型: {problem.type}")
            print(f"测试用例数据: {problem.test_cases}")
            
            if problem.test_cases:
                try:
                    import json
                    parsed = json.loads(problem.test_cases)
                    print(f"解析后的测试用例: {parsed}")
                    print(f"测试用例数量: {len(parsed) if isinstance(parsed, list) else '非数组格式'}")
                except Exception as e:
                    print(f"解析失败: {e}")
            else:
                print("没有测试用例数据")

if __name__ == '__main__':
    check_test_cases()
